//
//  DressController.m
//  婚礼纪
//
//  Created by dllo on 15/5/12.
//  Copyright (c) 2015年 蓝鸥. All rights reserved.
//

#import "DressController.h"
#import "ConnectModel.h"
#import "UIImageView+DownLoader.h"
@interface DressController ()<ConnectModelDelegate>

@property (nonatomic, retain) NSString * path;

@property (nonatomic, retain) NSDictionary * dic;

@end

@implementation DressController

- (void)dealloc
{
    [_Id release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)loadView
{
    [super loadView];
    self.navigationItem.title = @"商品详情";
    [self startConnect];
}

- (void)startConnect
{
    self.path = [NSString stringWithFormat:@"http://hunliji.com/products/%@.json", _Id];
    [ConnectModel connectUrlWith:_path delegate:self];
}

- (void)sendData:(NSData *)data
{
    self.dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    
    [self createView];
}

- (void)createView
{
    [self.view setBackgroundColor:[UIColor whiteColor]];
    NSDictionary * dic = [_dic objectForKey:@"product"];
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 69, 355, 500)];
    NSString * path = [dic objectForKey:@"photo_path"];
    [imageView setImageWithUrl:path placeHolder:nil];
    [self.view addSubview:imageView];
    [imageView release];
    
    UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(20, 570, 335, 40)];
    name.text = [dic objectForKey:@"introduce"];
    name.textAlignment = 1;
    [self.view addSubview:name];
    [name release];
    
    UILabel * price = [[UILabel alloc] initWithFrame:CGRectMake(140, 600, 95, 60)];
    NSString * aaa = [dic objectForKey:@"price"];
    NSString * pri = [NSString stringWithFormat:@"￥ %@", aaa];
    price.text = pri;
    price.textColor = [UIColor orangeColor];
    price.font = [UIFont boldSystemFontOfSize:25];
    price.textAlignment = 1;
    [self.view addSubview:price];
    [price release];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
